package org.example.module.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import org.example.module.common.SysHttpStatus;
import org.example.module.entity.SysUser;
import org.example.module.exception.DataNotFoundException;
import org.example.module.info.UserInfo;
import org.example.module.mapper.SysUserMapper;
import org.example.module.service.UserService;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    private final SysUserMapper userMapper;

    public UserServiceImpl(SysUserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public UserInfo queryUserByName(String name) {
        SysUser user = userMapper.selectByUserName(name);
        if (ObjectUtil.isEmpty(user)) {
            throw new DataNotFoundException(SysHttpStatus.DATA_NOTFOUND_EXCEPTION.getMsg());
        }
        UserInfo info = new UserInfo();
        BeanUtil.copyProperties(user, info);
        return info;
    }
}
